

axios.defaults.withCredentials=true;

new Vue({
    el:"#register",
    template:"<div><hr />" +
        "账号：<input id='username' type='text' v-model='username' /><br />" +
        "密码：<input id='password' type='password' v-model='password' /><br />" +
        "电话号码：<input id='telephone' type='text' v-model='telephone' /><br />" +
        "生日：<br />" +
        "性别：<br />" +
        "邮箱：<input id='email' type='text' v-model='e_mail' /><a href='#' @click.prevent='getCode'>发送验证码</a><br />" +
        "验证码：<input id='code' type='text' v-model='code' /><br />" +
        "<a href='#' @click.prevent='testCode'>测试验证码</a><br /> " +
        "<a href='#' @click.prevent='register'>注册</a> " +
        "</div>",
    data: {
        username: "",
        password: "123456",
        e_mail:"1060901278@qq.com",
        telephone:"18023649352",
        sex:1,
        birthday:"2020-05-20",
        code:"",
        info: null
    },
    methods:{
        getCode(){
            var urlCode = "http://localhost:8080/api/user/email";
            let dataCode = {email:this.e_mail};
            axios.post(urlCode,Qs.stringify(dataCode),{
                header:{
                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
                }
            })
                .then(function(response){
                    alert(response.data.message);
                })
                .catch(function(error){
                    console.log(error);
                });
        },
        register(){
            var urlRegist = "http://localhost:8080/api/user/regist";
            let dataRegist = {
                code:this.code,
                username:this.username,
                password:this.password,
                birthday: this.birthday,
                telephone: this.telephone,
                sex:this.sex,
                email:this.e_mail
            };
            axios.post(urlRegist,dataRegist,{
                header:{
                    'Content-Type': 'application/json',
                }
            })
                .then(function(response){
                    alert(response.data.message);
                })
                .catch(function(error){
                    console.log(error);
                });
        },
        testCode(){
            var url = "http://localhost:8080/api/user/code"
            axios.post(url,null,{
                header:{
                    'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
                }
            })
                .then(function(response){
                    alert(response.data);
                })
                .catch(function(error){
                    console.log(error);
                });
        }
    }
});
